package com.evil.application.pojo.dto.form.control.option;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.evil.application.pojo.entity.FormControlOption;
import com.evil.common.core.enums.SwitchEnum;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 表单控件下拉项返回实体
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
public class FormOptionRespDTO {

    /**
     * 选项id
     */
    private Long optionId;

    /**
     * 控件id
     */
    private Long controlId;

    /**
     * 下拉项url
     */
    private String optionUrl;

    /**
     * 下拉项名称
     */
    private String optionName;

    /**
     * 下拉项值
     */
    private String optionValue;

    /**
     * 父级选项id
     */
    private Long parentOptionId;

    /**
     * 是否默认(0:否, 1:是)
     */
    private Integer isDefault;

    /**
     * 是否其他选项(0:否, 1:是)
     */
    private Boolean beingOtherOpt;

    /**
     * 联动控件列表
     */
    private List<Long> linkControlIds;

    /**
     * 子级
     */
    private List<FormOptionRespDTO> childrenOptions;

    public FormOptionRespDTO() {
        this.isDefault = SwitchEnum.NO.getId();
        this.beingOtherOpt = false;
        this.linkControlIds = new ArrayList<>();
        this.childrenOptions = new ArrayList<>();
    }

    public FormOptionRespDTO(FormControlOption formControlOption) {
        this.isDefault = SwitchEnum.NO.getId();
        this.beingOtherOpt = false;
        this.linkControlIds = new ArrayList<>();
        this.childrenOptions = new ArrayList<>();
        BeanUtil.copyProperties(formControlOption, this);

        if (StringUtils.isNotBlank(formControlOption.getLinkControlIds())) {
            this.linkControlIds = JSON.parseArray(formControlOption.getLinkControlIds(), Long.class);
        }
    }
}
